package com.climber.spb_rabbitmq.spb_priority.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author frx
 * @version 1.0
 * @date 2022/7/25  22:31
 * desc:TTL队列 配置文件类代码
 */
@Configuration
public class RabbitMQConfig {

    public static final String X_EXCHANGE="X";
    public static final String ROUTING_KEY = "XP";
    public static final String QUEUE_P = "QP";

    @Bean("xExchange")
    public DirectExchange xExchange(){
        return new DirectExchange(X_EXCHANGE,false,false);
    }

    @Bean("queueP")
    public Queue queueD(){
        Map<String, Object> args = new HashMap<>();
        // 设置队列最大优先级
        args.put("x-max-priority", 10);
        return QueueBuilder.nonDurable(QUEUE_P).withArguments(args).build();
    }

    //声明队列 QD 绑定 Y 交换机
    @Bean
    public Binding queueDBindingY(@Qualifier("queueP") Queue queueP,
                                  @Qualifier("xExchange") DirectExchange xExchange){
        return BindingBuilder.bind(queueP).to(xExchange).with(ROUTING_KEY);
    }

}
